### STUDY 3 DATA PREPARATION

## set working directory 

metoo3 <- read.csv("study3_replication_raw.csv")


## Preprocessing data

## Create individual level baseline for measures from allegation stage

metoo3$resign_base <- metoo3$resign_alleg_1 ## resignation baseline

metoo3$likely_base <- metoo3$likely_alleg_1 ## belief baseline


## Stacking data by respondent-measurement stage

metoo3_1 <- metoo3 %>% dplyr::select(ResponseId, resign_base, likely_base, likely_alleg_1:resign_alleg_1, 
                                     metoo3_treatment_comm, metoo3_treatment_evidence)
## allegation stage measures

metoo3_2 <- metoo3 %>% dplyr::select(ResponseId, resign_base, likely_base, likely_2_1:resign_2_1, 
                                     metoo3_treatment_comm, metoo3_treatment_evidence)
## communication OR evidence stage when 

metoo3_3 <- metoo3 %>% dplyr::select(ResponseId, resign_base, likely_base, likely_3_1:resign_3_1, 
                                     metoo3_treatment_comm, metoo3_treatment_evidence)
## evidence OR communication stage


metoo3_long <- dplyr::bind_rows(metoo3_1, metoo3_2, metoo3_3) ## bind data

metoo3_long <- unite(metoo3_long, "resign", c(resign_alleg_1, resign_2_1, resign_3_1), 
                     na.rm = TRUE, remove = FALSE) ## collapse measures into single outcome

metoo3_long <- unite(metoo3_long, "likely", c(likely_alleg_1, likely_2_1, likely_3_1), 
                     na.rm = TRUE, remove = FALSE)

metoo3_long$likely <- as.numeric(metoo3_long$likely)
metoo3_long$resign <- as.numeric(metoo3_long$resign)



## Indexing all experimental groups


metoo3_long$treatment <- NA

## CONTROL GROUP (ALLEGATION STAGE, first stage)

metoo3_long$treatment[!is.na(metoo3_long$resign_alleg_1)] <- "control" 
## in stacked data, if first resignation measure is not NA: resp-measure is pre-treatment: 
## equivalent to read only allegation


## ONLY EVIDENCE GROUPS (When evidence comes before (second stage): : metoo3_treatment_evidence == 'before')

metoo3_long$treatment[!is.na(metoo3_long$resign_2_1) & 
                        metoo3_long$metoo3_treatment_comm == "denial" &
                        metoo3_long$metoo3_treatment_evidence == "before"] <- "evidence only"
## in stacked data, if the second resignation measure is not NA: resp-measure is from second stage
## if communication is 'denial' and the respondent was allocated to receive the evidence 'before': 
## equivalent to only evidence group (second stage)

metoo3_long$treatment[!is.na(metoo3_long$resign_2_1) & 
                        metoo3_long$metoo3_treatment_comm == "apology" &
                        metoo3_long$metoo3_treatment_evidence == "before"] <- "evidence only"
## in stacked data, if the second resignation measure is not NA: resp-measure is from second stage
## if communication is 'apology' and the respondent was allocated to receive the evidence 'before': 
## equivalent to only evidence group (second stage)



## FIRST EVIDENCE THEN COMMUNICATION GROUPS

metoo3_long$treatment[!is.na(metoo3_long$resign_3_1) & 
                        metoo3_long$metoo3_treatment_comm == "denial" &
                        metoo3_long$metoo3_treatment_evidence == "before"] <- "evidence then denial"
## in stacked data, if the third resignation measure is not NA: resp-measure is from third stage
## if communication is 'denial' and the respondent was allocated to receive the evidence 'before': 
## this is equivalent to first evidence (2nd stage) then denial communication (third stage) group

metoo3_long$treatment[!is.na(metoo3_long$resign_3_1) & 
                        metoo3_long$metoo3_treatment_comm == "apology" &
                        metoo3_long$metoo3_treatment_evidence == "before"] <- "evidence then apology"
## in stacked data, if the third resignation measure is not NA: resp-measure is from third stage
## if communication is 'apology' and the respondent was allocated to receive the evidence 'before': 
## this is equivalent to first evidence (2nd stage) then apology communication (third stage) group


## ONLY COMMUNICATION GROUPS (when evidence comes after (third stage): metoo3_treatment_evidence == 'after')

metoo3_long$treatment[!is.na(metoo3_long$resign_2_1) & 
                        metoo3_long$metoo3_treatment_comm == "denial" &
                        metoo3_long$metoo3_treatment_evidence == "after"] <- "denial only"
## in stacked data, if the second resignation measure is not NA: resp-measure is from second stage
## if communication is 'denial' and the respondent was allocated to receive the evidence 'after': 
## equivalent to only denial communication group (second stage)


metoo3_long$treatment[!is.na(metoo3_long$resign_2_1) & 
                        metoo3_long$metoo3_treatment_comm == "apology" &
                        metoo3_long$metoo3_treatment_evidence == "after"] <- "apology only"
## in stacked data, if the second resignation measure is not NA: resp-measure is from second stage
## if communication is 'apology' and the respondent was allocated to receive the evidence 'after': 
## equivalent to only apology communication group (second stage)


## FIRST COMMUNICATION THEN EVIDENCE GROUPS

metoo3_long$treatment[!is.na(metoo3_long$resign_3_1) & 
                        metoo3_long$metoo3_treatment_comm == "denial" &
                        metoo3_long$metoo3_treatment_evidence == "after"] <- "denial then evidence"
## in stacked data, if the third resignation measure is not NA: resp-measure is from third stage
## if communication is 'denial' and the respondent was allocated to receive the evidence 'after': 
## this is equivalent to first denial (2nd stage) then evidence (third stage) group


metoo3_long$treatment[!is.na(metoo3_long$resign_3_1) & 
                        metoo3_long$metoo3_treatment_comm == "apology" &
                        metoo3_long$metoo3_treatment_evidence == "after"] <- "apology then evidence"
## in stacked data, if the third resignation measure is not NA: resp-measure is from third stage
## if communication is 'apology' and the respondent was allocated to receive the evidence 'after': 
## this is equivalent to first apology (2nd stage) then evidence (third stage) group


metoo3_long$treatment <- as.factor(metoo3_long$treatment)


## final dataset for study 3 analysis
metoo3_long <- metoo3_long %>% dplyr::select(ResponseId, treatment, resign, likely, resign_base, likely_base)
#write.csv(metoo3_long, "study3_replication_analysis.csv")

